﻿<UserControl x:Class="Sker.Controls.SearchBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Height="30"
             Width="485">
    <Grid>
        <Border Name="searchBorder"
                Background="White"
                BorderThickness="0.7"
                BorderBrush="Black"
                Height="{Binding Path=Height, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                Width="{Binding Path=Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
            <TextBox Name="searchBox"
                     VerticalAlignment="Stretch"
                     HorizontalAlignment="Stretch"
                     VerticalContentAlignment="Center"
                     FontSize="15"
                     FontStyle="Italic"
                     Foreground="Gray"
                     BorderBrush="Transparent"
                     Margin="0.0,0.0,1.0,0.5"
                     GotKeyboardFocus="searchBox_GotKeyboardFocus"
                     LostKeyboardFocus="searchBox_LostKeyboardFocus"
                     Loaded="searchBox_Loaded"
                     KeyUp="searchBox_KeyUp"
                     PreviewKeyDown="searchBox_PreviewKeyDown"
                     TextChanged="searchBox_TextChanged">
                <!--<TextBox.Style>
                    <Style TargetType="TextBox">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Value="{x:Null}">
                                <Setter Property="FontWeight" Value="Normal"/>
                            </DataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Path=SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Value="{x:Null}"/>
                                </MultiDataTrigger.Conditions>
                                <MultiDataTrigger.Setters>
                                    <Setter Property="FontWeight" Value="Normal"/>
                                </MultiDataTrigger.Setters>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>-->
                <TextBox.Background>
                    <ImageBrush ImageSource="img/searchico.png"
                                AlignmentX="Right"
                                Stretch="Uniform" />
                </TextBox.Background>
            </TextBox>
        </Border>
        <Popup Name="searchPopup"
               HorizontalOffset="-1"
               VerticalOffset="1"
               PopupAnimation="Slide"
               StaysOpen="False"
               Placement="Bottom"
               MinHeight="0"
               Height="Auto"
               Width="{Binding ElementName=searchBorder, Path=Width}"
               PlacementTarget="{Binding ElementName=searchBox}"
               Closed="searchPopup_Closed">
            <Popup.Resources>
                <SolidColorBrush x:Key="DisabledForegroundBrush"
                                 Color="#FF15428B" />

                <SolidColorBrush x:Key="SelectedBorderBrush"
                                 Color="#C0A776" />

                <LinearGradientBrush x:Key="SelectedBackgroundBrush"
                                     StartPoint="0.5,0"
                                     EndPoint="0.5,1">
                    <GradientStop Offset="0"
                                  Color="#FFFFFDDE" />
                    <GradientStop Offset="0.4"
                                  Color="#FFFFE795" />
                    <GradientStop Offset="0.4"
                                  Color="#FFF6CF57" />
                    <GradientStop Offset="1"
                                  Color="#FFFFE9A4" />
                </LinearGradientBrush>
                
                <Style TargetType="ListBoxItem"
                       BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <EventSetter Event="MouseMove"
                                 Handler="searchList_MouseMove" />
                    <Setter Property="SnapsToDevicePixels"
                            Value="true" />
                    <Setter Property="OverridesDefaultStyle"
                            Value="true" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Border Name="Border"
                                        BorderThickness="0,1"
                                        CornerRadius="0"
                                        Padding="3"
                                        SnapsToDevicePixels="True">
                                    <ContentPresenter />
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected"
                                             Value="true">
                                        <Setter TargetName="Border"
                                                Property="Background"
                                                Value="{StaticResource SelectedBackgroundBrush}" />
                                        <Setter TargetName="Border"
                                                Property="BorderBrush"
                                                Value="{StaticResource SelectedBorderBrush}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled"
                                             Value="false">
                                        <Setter Property="Foreground"
                                                Value="{StaticResource DisabledForegroundBrush}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Popup.Resources>
            <StackPanel Orientation="Vertical"
                        HorizontalAlignment="Stretch"
                        Background="White">
                <ListBox Name="searchList"
                         SelectionMode="Single"
                         HorizontalAlignment="Stretch"
                         MaxHeight="250"
                         MinHeight="0"
                         Height="Auto"
                         BorderBrush="Silver"
                         BorderThickness="1,0,1,1"
                         Loaded="searchList_Loaded"
                         MouseLeftButtonUp="searchList_MouseLeftButtonUp">
                    <ListBox.Style>
                        <Style TargetType="ListBox">
                        </Style>
                    </ListBox.Style>
                </ListBox>
                <Label Name="itemsCount"
                       HorizontalAlignment="Stretch"
                       FontStyle="Italic"
                       FontSize="11"
                       VerticalContentAlignment="Center"
                       HorizontalContentAlignment="Right"
                       Height="20"
                       Margin="0"
                       Padding="3,0,3,2"
                       BorderBrush="{Binding Path=BorderBrush, ElementName=searchList}"
                       BorderThickness="{Binding Path=BorderThickness, ElementName=searchList}" />
                <Label Name="noResults"
                       HorizontalAlignment="Stretch"
                       Visibility="Collapsed"
                       Content="No se encontraron resultados."
                       FontSize="15"
                       FontStyle="Italic"
                       BorderBrush="{Binding Path=BorderBrush, ElementName=searchList}"
                       BorderThickness="{Binding Path=BorderThickness, ElementName=searchList}" />
            </StackPanel>
        </Popup>
    </Grid>
</UserControl>
